package com.hzlx.qualityStandards.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.hzlx.qualityStandards.domain.MesQualityStandards;
import com.hzlx.qualityStandards.service.IMesQualityStandardsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 质量检验标准库（定义产品/物料/工序的检验规则）Controller
 * 
 * @author ruoyi
 * @date 2025-07-01
 */
@RestController
@RequestMapping("/quality")
public class MesQualityStandardsController extends BaseController
{
    @Autowired
    private IMesQualityStandardsService mesQualityStandardsService;

    /**
     * 查询质量检验标准库（定义产品/物料/工序的检验规则）列表
     */
    @RequiresPermissions("quality-service:qualityStandards:list")
    @GetMapping("/qualityStandards/list")
    public TableDataInfo list(MesQualityStandards mesQualityStandards)
    {
        startPage();
        List<MesQualityStandards> list = mesQualityStandardsService.selectMesQualityStandardsList(mesQualityStandards);
        return getDataTable(list);
    }

    /**
     * 导出质量检验标准库（定义产品/物料/工序的检验规则）列表
     */
    @RequiresPermissions("quality-service:qualityStandards:export")
    @Log(title = "质量检验标准库（定义产品/物料/工序的检验规则）", businessType = BusinessType.EXPORT)
    @PostMapping("/qualityStandards/export")
    public void export(HttpServletResponse response, MesQualityStandards mesQualityStandards)
    {
        List<MesQualityStandards> list = mesQualityStandardsService.selectMesQualityStandardsList(mesQualityStandards);
        ExcelUtil<MesQualityStandards> util = new ExcelUtil<MesQualityStandards>(MesQualityStandards.class);
        util.exportExcel(response, list, "质量检验标准库（定义产品/物料/工序的检验规则）数据");
    }

    /**
     * 获取质量检验标准库（定义产品/物料/工序的检验规则）详细信息
     */
    @RequiresPermissions("quality-service:qualityStandards:query")
    @GetMapping(value = "/qualityStandards/{standardId}")
    public AjaxResult getInfo(@PathVariable("standardId") String standardId)
    {
        return success(mesQualityStandardsService.selectMesQualityStandardsByStandardId(standardId));
    }

    /**
     * 新增质量检验标准库（定义产品/物料/工序的检验规则）
     */
    @RequiresPermissions("quality-service:qualityStandards:add")
    @Log(title = "质量检验标准库（定义产品/物料/工序的检验规则）", businessType = BusinessType.INSERT)
    @PostMapping("/qualityStandards")
    public AjaxResult add(@RequestBody MesQualityStandards mesQualityStandards)
    {
        return toAjax(mesQualityStandardsService.insertMesQualityStandards(mesQualityStandards));
    }

    /**
     * 修改质量检验标准库（定义产品/物料/工序的检验规则）
     */
    @RequiresPermissions("quality-service:qualityStandards:edit")
    @Log(title = "质量检验标准库（定义产品/物料/工序的检验规则）", businessType = BusinessType.UPDATE)
    @PutMapping("/qualityStandards")
    public AjaxResult edit(@RequestBody MesQualityStandards mesQualityStandards)
    {
        return toAjax(mesQualityStandardsService.updateMesQualityStandards(mesQualityStandards));
    }

    /**
     * 删除质量检验标准库（定义产品/物料/工序的检验规则）
     */
    @RequiresPermissions("quality-service:qualityStandards:remove")
    @Log(title = "质量检验标准库（定义产品/物料/工序的检验规则）", businessType = BusinessType.DELETE)
	@DeleteMapping("/qualityStandards/{standardIds}")
    public AjaxResult remove(@PathVariable String[] standardIds)
    {
        return toAjax(mesQualityStandardsService.deleteMesQualityStandardsByStandardIds(standardIds));
    }
}
